package com.lock.aspectj;

import com.lock.util.OrderLockUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by hx on 2017/7/21.
 */
@Aspect
@Component
public class LockInterceptor {
    @Around("@annotation(com.lock.annotation.ZKLock)")
    public Object srt(ProceedingJoinPoint jp){
        OrderLockUtil orderLockUtil = new OrderLockUtil();
        Object result = null;
        try {
            if (orderLockUtil.entrance()) {
                result = jp.proceed();
                orderLockUtil.deleteLock();
            } else {
                result = jp.proceed();
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return result;
    }
}
